<?php
class order_product extends api_controllor 
{
    var $uid;
    var $_sn = '';
    public function __construct($get_param)
    {
        parent::__construct($get_param);
        
        
    }
    
    public function run()
    {
        $this->check_para();
        
        
        $this->uid = $this->visitor['uid'];
        
        $oProduct = K::load_mod('product');
        $oProduct->get_by_sn($this->_sn) or $this->busy();
        $aProduct = $oProduct->get_data();
        if(!$aProduct || $aProduct['stat'] != K_COMMON_YES)
            $this->err_output(K_SYSCODE_ERROR);
            
        $pid = $aProduct['id'];
            
        $oBuy = K::load_mod('product_buy');
        $oBuy->is_exist_uid_pid($this->uid , $pid , $is_exist) or $this->busy();
        if($is_exist)
            $this->suc_output();
        else 
        {
            
            $oBuy->create($this->uid , $pid) or $this->busy();
            
            $oMember = K::load_mod('member');
            $oMember->increase_order($this->uid);
            
            $this->suc_output();
        }
    }
    
    public function check_para()
    {
        $this->_sn = $this->get_input('sn');
        
        if(!is_product_sn($this->_sn))
        {
            $this->err_output(K_SYSCODE_ERROR);
        }
    }
}

?>